import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:honeypotflutter/modules/signFor/api/signForApi.dart';
import 'package:honeypotflutter/modules/signFor/model/signForModel.dart';
import 'package:honeypotflutter/modules/signFor/view/signFor_item.dart';
import 'package:honeypotflutter/publicBussine/view/bussine_button.dart';
import 'package:honeypotflutter/public/views/public_appBar.dart';
import 'package:honeypotflutter/public/views/public_future.dart';

class SignForPage extends StatefulWidget {
  const SignForPage({super.key});

  @override
  State<SignForPage> createState() => _SignForPageState();
}

class _SignForPageState extends State<SignForPage> {
  List<SignForModel> _itemModelList = [];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: HLAppBar(
        navigationTitle: "签收设置",
      ),
      body: HLFuture<List<SignForModel>>(
          future: SignForApi.requestSignForList(),
          snap: (AsyncSnapshot<List<SignForModel>> snap) {
            if (snap.data == null || snap.data!.isEmpty) {
              return null;
            }
            _itemModelList.addAll(snap.data!);
            return ListView.builder(
                itemCount: _itemModelList.length,
                itemBuilder: (BuildContext context, int index) {
                  return SignForItem(itemModel: _itemModelList[index]);
                });
          }),
      bottomSheet: MGButton(
        title: "提交",
        backColor: Colors.transparent,
        margin: EdgeInsets.all(16),
        buttonAction: () {
          List jsonList = _itemModelList.map((e) => e.toJson()).toList();
          SignForApi.setSignFor(jsonList).then((value) => Get.back());
        },
      ),
    );
  }
}
